﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LeetCode.simple
{
    public class StackQueue
    {

        private Stack<int> stackIn = new Stack<int>();
        private Stack<int> stackOut = new Stack<int>();
        public void Push(int x)
        {
            if (stackOut.Count == 0 && stackIn.Count == 0)
            {
                stackOut.Push(x);
            }
            else
            {
                stackIn.Push(x);
            }
        }

        public int Pop()
        {
            if (stackOut.Count == 0 && stackIn.Count > 0)
            {
                while (stackIn.Count > 0)
                {
                    stackOut.Push(stackIn.Pop());
                }
            }
            return stackOut.Pop();
        }

        public int Peek()
        {
            if (stackOut.Count == 0 && stackIn.Count > 0)
            {
                while (stackIn.Count > 0)
                {
                    stackOut.Push(stackIn.Pop());
                }
            }
            return stackOut.Peek();
        }

        public bool Empty()
        {
            return stackOut.Count == 0 && stackIn.Count == 0;
        }
    }
}
